package com.itwn.web;

import com.itwn.entity.User;
import com.itwn.service.UserService;
import com.itwn.util.SpringUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/add")
public class AddServlet extends BaseServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String uname = req.getParameter("uname");
        String pass = req.getParameter("pass");
        String sex = req.getParameter("sex");
        double salary = Double.parseDouble(req.getParameter("salary"));
        User user = new User(uname, pass, sex, salary);
        UserService userService = (UserService) SpringUtil.getBean("userServiceImpl");
        int i = userService.addUser(user);
        resp.sendRedirect(req.getContextPath()+"/list");
    }
}
